package conn;

import java.sql.*;

public class Data {
	private Dataconn conn = new Dataconn();
	//private Statement stmt;
	private ResultSet rs;

	public int getRowCount(String strSql) {
		int intCount = 0;
		//Dataconn conn = new Dataconn();
		try {
			
			rs = conn.executeQuery("Select count(*) from " + strSql);
			//System.out.println("rs_tostring:"+rs.toString());
			if (rs.next()) {
				intCount = rs.getInt(1);
				//System.out.println("intCount:"+intCount);
			} else {
				intCount = -1;
			}

		} catch (Exception e) {
			intCount = -2;
			System.err.println(e.getMessage());
			e.printStackTrace();
		} 
		finally 
		{
			conn.closeStmt();
			conn.closeConn();
			return intCount;
		}
	}
	
	
	
	public int insert(String sql){
		int count=0;
		try{
			conn.executeUpdate(sql);
		}
		catch(Exception e){
			count=-2;
		System.err.println(e.getMessage());
		e.printStackTrace();
		}finally{
			conn.closeConn();
			return count;
		}
	}
public int update(String sql){
	int count =0;
	try{
		
		conn.executeUpdate(sql);
		
	}
	catch(Exception e){
		count=-2;
	System.err.println(e.getMessage());
	e.printStackTrace();
	}finally{
		conn.closeConn();
		return count;
	}
}

}



